/**
 * 0209
 *
 * @Author : Ruoyu Wang
 * @DateTime : 2024/8/12 20:56
 */

#include <iostream>
#include <vector>

using namespace std;

class Solution {
public:
    int minSubArrayLen(int target, vector<int> &nums) {
        int l = 0;
        int r = 0;
        long long sum = 0;
        int res = 0x3f3f3f3f;

        while (r < nums.size()) {
            sum += nums[r++];
            while (sum >= target) {
                res = min(res, r - l);
                sum -= nums[l++];
            }
        }
        if (res == 0x3f3f3f3f) res = 0;
        return res;
    }
};

int main() {
    Solution sl;
    int target = 7;
    vector<int> nums = {2, 3, 1, 2, 4, 3};
    sl.minSubArrayLen(target, nums);
    return 0;
}